﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using Data;
using System.Data;
namespace Business
{
   public class BaoCaoTonService
    {
       public static bool Exists(DateTime thang)
       {
           return BaoCaoTonRepository.Exists(thang);
       }
       public static  BaoCaoTonDTO GetBaoCaoTonByThang(DateTime thang)
       {
           return BaoCaoTonRepository.GetBaoCaoTonByThang(thang);
       }
       public static int GetCurrentID()
       {
           return BaoCaoTonRepository.GetCurrentID();
       }
       public static void Insert(BaoCaoTonDTO baoCaoTon)
       {
           BaoCaoTonRepository.Insert(baoCaoTon);
       }
       public static DataTable LapBaoCao(DateTime thang)
       {
           DataTable kq = new DataTable();
           BaoCaoTonDTO baoCaoTon=BaoCaoTonService.GetBaoCaoTonByThang(thang);
           if (baoCaoTon == null)
               return null;
           int maBaoCao = baoCaoTon.MaBaoCaoTon;
           List<ChiTietBaoCaoTonDTO> listChiTietBaoCaoTon = ChiTietBaoCaoTonRepository.GetChiTietByMaBaoCao(maBaoCao);
           kq = ConvertTo.DataTable(listChiTietBaoCaoTon);
           kq.Columns.Add("TenSach");
           for (int i = 0; i < kq.Rows.Count; i++)
           {
               int maSach=(int)kq.Rows[i]["MaSach"];
               kq.Rows[i]["TenSach"] = SachRepository.GetSachByMaSach(maSach).TenSach;
           }
           
           return kq;
       }
    }
}
